/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.sourceforge.slcwsn.monitorapp;

import com.google.code.xbeejavaapi.api.exception.XBeeOperationFailedException;
import java.text.DateFormat;
import java.util.Date;
import net.sourceforge.slcwsn.event.EventVisitor;
import net.sourceforge.slcwsn.event.LostSensorMessagesEvent;
import net.sourceforge.slcwsn.event.PIRDetectionEvent;
import net.sourceforge.slcwsn.event.SensorAliveEvent;
import net.sourceforge.slcwsn.event.SensorChangedEvent;
import net.sourceforge.slcwsn.event.SensorDiscoveredEvent;
import net.sourceforge.slcwsn.event.SuperNodeDiscoveredEvent;
import org.apache.log4j.Logger;

/**
 *
 * @author David Miguel Antunes <davidmiguel [ at ] antunes.net>
 */
public class EventShortDescriptor implements EventVisitor {

    private static final Logger logger = Logger.getLogger(EventShortDescriptor.class);
    private String description;

    public void visit(SensorDiscoveredEvent event) {
        description = "SensorDiscoveredEvent from sensor " + event.getSensor() + " at " + DateFormat.getDateTimeInstance().format(new Date(event.getTimestamp()));
    }

    public void visit(SensorAliveEvent event) {
        description = "SensorAliveEvent from sensor " + event.getSensor() + " at " + DateFormat.getDateTimeInstance().format(new Date(event.getTimestamp()));
    }

    public void visit(PIRDetectionEvent event) {
        description = "PIRDetectionEvent from sensor " + event.getSensor() + " at " + DateFormat.getDateTimeInstance().format(new Date(event.getTimestamp()));
    }

    public String getDescription() {
        return description;
    }

    public void visit(SuperNodeDiscoveredEvent event) {
        try {
            description = "SuperNodeDiscoveredEvent, sensor with address " + event.getNode().getxBee().getSerialNumber() + " at " + DateFormat.getDateTimeInstance().format(new Date(event.getTimestamp()));
        } catch (XBeeOperationFailedException ex) {
            logger.error(ex);
            description = "Exception: " + ex.getMessage();
        }
    }

    public void visit(LostSensorMessagesEvent event) {
        description = "LostSensorMessagesEvent from sensor " + event.getSensor() + " at " + DateFormat.getDateTimeInstance().format(new Date(event.getTimestamp())) + " (" + event.getnMessages() + " messages)";
    }

    public void visit(SensorChangedEvent event) {
        description = "SensorChangedEvent";
    }
}
